package cn.tedu.bonfire.front.content.dao.persist.repository.impl;

import cn.tedu.bonfire.common.pojo.vo.PageData;
import cn.tedu.bonfire.common.util.PageInfoToPageDataConverter;
import cn.tedu.bonfire.front.content.dao.persist.mapper.CommentMapper;
import cn.tedu.bonfire.front.content.dao.persist.repository.ICommentRepository;
import cn.tedu.bonfire.front.content.pojo.entity.Comment;
import cn.tedu.bonfire.front.content.pojo.vo.CommentListItemVO;
import cn.tedu.bonfire.front.content.pojo.vo.CommentStandardVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;


@Slf4j
@Repository
public class CommentRepositoryImpl implements ICommentRepository {
    @Autowired
    private CommentMapper commentMapper;

    public CommentRepositoryImpl() {
        log.info("创建存储库对象：CommentRepositoryImpl");
    }

    @Override
    public int insert(Comment comment) {
        log.debug("开始执行【插入评论】的数据访问，参数：{}", comment);
        return commentMapper.insert(comment);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据ID删除评论】的数据访问，参数：{}", id);
        return commentMapper.deleteById(id);
    }

    @Override
    public int updateById(Comment comment) {
        log.debug("开始执行【更新评论】的数据访问，参数：{}", comment);
        return commentMapper.updateById(comment);
    }

    @Override
    public PageData<CommentListItemVO> listByArticle(Long articleId, Integer pageNum, Integer pageSize) {
        log.debug("开始执行【根据文章查询评论列表】的数据访问，文章：{}，页码：{}，每页记录数：{}", articleId, pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<CommentListItemVO> list = commentMapper.listByArticle(articleId);
        PageInfo<CommentListItemVO> pageInfo = new PageInfo<>(list);
        PageData<CommentListItemVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);

        return pageData;
    }

    @Override
    public String getCommentContentById(Long commentId) {
        return commentMapper.getCommentContentById(commentId);
    }
    @Override
    public Long userCommentById(Long userId) {
        return commentMapper.selectComments();
    }

}
